package com.anjie.powerproject.repository;

import com.anjie.powerproject.entity.RelationshipCom;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


public interface RelationshipComRepository extends JpaRepository<RelationshipCom,Integer> {
    List<RelationshipCom> findRelationshipComsById(Integer id);

    List<RelationshipCom> findRelationshipComsByStgyCode(Integer stgyCode);

    void deleteRelationshipComsByIdAndStgyCode(Integer id,Integer stgyCode);

    @Transactional
    void deleteAllByStgyCode(Integer stgyCode);

    List<RelationshipCom> findRelationshipComsByDeviceFromAndDeviceToAndStgyCode(Integer deviceFrom,Integer deviceTo,Integer stgyCode);

    @Transactional
    void deleteRelationshipComsByDeviceFromAndDeviceToAndStgyCode(Integer deviceFrom,Integer deviceTo,Integer stgyCode);

    List<RelationshipCom> findRelationshipComsByGraphId(Integer graphID);

    List<RelationshipCom> findRelationshipComsByDeviceFromAndDeviceToAndGraphId(Integer deviceFrom,Integer deviceTo,Integer graphId);

    @Query(nativeQuery = true,value = "select MAX(stgy_code) from relationship_com ")
    Integer findMaxStgyCode();

    @Transactional
    void deleteRelationshipComsByGraphId(Integer graphId);

    List<RelationshipCom> findRelationshipComByDeviceTo(Integer deviceTo);
}
